package approve.adapter;

import java.util.List;

import model.pojo.Employee;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import approve.action.App_ViewForm11;
import approve.action.R;

public class AdapterListApprover11 extends BaseAdapter implements OnItemClickListener{
	App_ViewForm11 context;
	private List<Employee> lstEmpl;
	String strid;
	ViewHolder holder;
	
	public AdapterListApprover11(App_ViewForm11 context,List<Employee> lst){
		this.context = context;
		this.lstEmpl = lst;
	}
	 

	@Override
	public int getCount() {
		return lstEmpl.size();
	}

	@Override
	public Object getItem(int arg0) {
		return lstEmpl.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertview, ViewGroup arg2) {
		final Employee employee = lstEmpl.get(position);
		
		if(convertview==null){
			holder = new ViewHolder();
			
			LayoutInflater a=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertview = a.inflate(R.layout.adapter_list_approver,arg2, false);
			
			holder.namempl = (TextView)convertview.findViewById(R.id.txtemp11);
			holder.imageView1=(ImageView)convertview.findViewById(R.id.imageDeleteEmp11);
			
			convertview.setTag(holder);
		}else{
			holder =  (ViewHolder)convertview.getTag();
		}
		
		holder.namempl.setText(employee.getFullName());
		
		holder.imageView1.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				if(lstEmpl.contains(employee)){
					context.getListemployee_11().remove(employee);
					context.getApprover11().notifyDataSetChanged();
				}
			}
		});
		return convertview;
	}


	public List<Employee> getLstEmpl() {
		return lstEmpl;
	}


	public void setLstEmpl(List<Employee> lstEmpl) {
		this.lstEmpl = lstEmpl;
	}


	public String getStrid() {
		strid="";
		if(lstEmpl!=null && lstEmpl.size()>0){
			for(int i=0;i<lstEmpl.size();i++){
				if(strid.equals("")){
					strid="'"+lstEmpl.get(i).getIdemployee()+"'";
				}else{
					strid+=",'"+lstEmpl.get(i).getIdemployee()+"'";;
				}
			}
		}
		return strid;
	}


	public void setStrid(String strid) {
		this.strid = strid;
	}


	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		
	}
	
	public static class ViewHolder{
		 TextView namempl;
		 ImageView imageView1;
	}
}
